/**
 * @(#) FileUploadProxy.as
 *
 * @date		2009. 03. 11.
 * @version		1.0
 * @author		Park, JuneHo
 * @description	 공지사항 쓰기 - Proxy
 * 				공지사항 조회하는 Model Logic 
 */
package com.skt.common_hr.empcont.model
{
	//import com.skt.common_hr.notice.NoticeFacade;
	//import com.skt.common_hr.notice.model.vo.NoticeFileUpLoadVO;
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.empcont.EmpcontFacade;
	import com.skt.common_hr.empcont.model.vo.IfileVO;
	import com.wcl.dataloader.*;
	import com.wcl.utils.AlertHelper;
	
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class FileUploadProxy extends CommonProxy
	{
		public static const NAME:String = "FileUploadProxy";

		public var writeKey:String;
		public var FILE_URL:String;
		public var I_FILE_SIZE:String;
		public var I_FILE_EXT:String;


		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function FileUploadProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		

		public function fileUpload(fileInfo:IfileVO, ACTIO:String):void
		{
			var params:Object = new Object();
			params["I_PERNR"]		= Variables.myPernr;			
			params["I_ACTIO"]		= ACTIO;
						
			var table:Array = new Array();
			table.push(fileInfo);
 			var tables:Object = new Object();
			tables["ITAB"] = table;
			saveData("Z_HR_EC04", params, tables, result, fault);
		}

		public function attachDel(vo:IfileVO,setFunc:Function):void
		{
			var params:Object = new Object();
			params["I_PERNR"]		= Variables.myPernr;			
			params["I_ACTIO"]		= "DEL";
						
			var obj:Object = {};
			obj.DCODE = vo.DCODE;	
					
			var table:Array = new Array();
			table.push(obj);
			
 			var tables:Object = new Object();
			tables["ITAB"] = table;
			saveData("Z_HR_EC04", params, tables, attachDelResult, fault, setFunc);
		}		

		public function attachDelResult(event:ResultEvent):void
		{
			if(retCode==0) {
				event.result.func();
			}
		}
						
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////


		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(event.result["RETCODE"]==0) {
				FILE_URL = event.result["FILE_URL"];
				trace("succeed to file upload");
				facade.sendNotification(EmpcontFacade.FILE_UPLOAD_COMPLETE, this);
			}
			else {
				trace( "failed to load notice: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				FILE_URL = "";
				AlertHelper.showMessage("("+event.result["RETCODE"] + ") "+event.result["RETTEXT"], "오류");
				facade.sendNotification(EmpcontFacade.FILE_UPLOAD_FAILED, this);
			}
			CursorManager.removeBusyCursor();
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			FILE_URL = "";
			trace("Fault message in NoticeProxy: " + event.fault.faultString);
			AlertHelper.showMessage("파일 업로드에 문제가 발생했습니다.", "오류");
			facade.sendNotification(EmpcontFacade.FILE_UPLOAD_FAILED, this);
			CursorManager.removeBusyCursor();
		}
		




		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
	}
}